package com.hualian.util.file;

import java.io.File;
import java.io.IOException;

import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartRequest;

public class FileUtil {

	/**
	 * 文件上传
	 * @param fileName
	 * @param dirFileName
	 * @param req
	 * @return
	 */
	public static final String upload(String fileName,String dirFileName,MultipartRequest req){
		MultipartFile file=req.getFile(fileName);
		String suffix=file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
		dirFileName+=suffix;
		File dir=new File(dirFileName);
		try {
			file.transferTo(dir);
		} catch (IllegalStateException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		file=null;
		return dir.exists()?suffix:"";
	}
}
